<template>
	<view v-if="pageData && pageData.length">
		<view class="plate">
			<titleBox title="服务内容"></titleBox>
			<view v-for="(item, index) in pageData" :key="index" class="WapBox">
				<ServerBuy :Buy="Buy" :pageData="item"></ServerBuy>

				<view class="serveList" :class="{ Used: subItem.state == 1 }" @click="Usede(subItem)"
					v-for="(subItem, subIndex) in item.use_log" :key="subIndex">
					<view class="iconfont icon-yishiyong color" v-if="Buy && subItem.state == 1"></view>
					<view class="product">
						<view class="serial" v-if="Buy">{{ subItem.item_id }}</view>
						<image :src="$imgUrls(subItem.img)" mode="aspectFill" class="product_img" v-if="subItem.img">
						</image>
					</view>
					<view class="product_content_buy" v-if="Buy">
						<view class="flex-1 d-flex f-column j-sb">
							<text class="ellipsis title size30 m-top10">{{ subItem.name }}</text>
							<text class="price size32 m-bot10" v-if="subItem.price">{{ subItem.price }}</text>
						</view>
						<view class="Options">
							<view class="Options-list" @click.stop="handleShare(subItem)">
								分享好友
								<button class="shareBtn" open-type="share" :data-id="subItem.id"></button>
							</view>
							<view class="Options-list">立即使用</view>
						</view>
					</view>
					<view class="product_content" v-else>
						<text class="ellipsis title size30">{{ subItem.name }}</text>
						<text class="ellipsis Abstract size28">{{ subItem.info }}</text>
						<view class="row j-sb a-center">
							<view class="d-flex f-column">
								<text class="color_99 size26">{{ subItem.times }}次</text>
								<text class="price size28 m-top8">￥{{ subItem.price }}</text>
							</view>
							<view class="look a-self-end">查看详情</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="Pop" v-if="Show">
			<useNow></useNow>
			<view class="iconfont icon-guanbi white size60 p-top30" @click.stop="Show = false"></view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import ServerBuy from '@/subCard/components/ServerBuy.vue';
	import titleBox from '@/subCard/components/titleBox.vue';
	import useNow from '@/subCard/components/useNow.vue';
	export default {
		props: ['Buy', 'pageData'],
		components: {
			ServerBuy,
			titleBox,
			useNow
		},
		data() {
			return {
				headImg: 'https://msraimgcdn.mogoie.com/6099/1709797684310.JPG',
				Show: false
			};
		},
		methods: {
			Usede(subItem) {
				if (!this.Buy) return;
				this.toUrl(`/subCard/userDetails?id=${subItem.id}`);
			},
			handleShare(subItem) {
				this.$emit('handleShare', subItem);
			}
		},
		computed: {
			...mapState(['color'])
		}
	};
</script>

<style lang="scss" scoped>
	.plate {
		width: 690rpx;
		margin: 0 auto;
		background-color: #ffffff;
		padding: 20rpx;
		border-radius: 10rpx;
		margin-top: 24rpx;
	}

	.WapBox {
		padding-bottom: 20rpx;
		padding-top: 20rpx;
		border-bottom: 1px dotted #000;
	}

	.WapBox:last-child {
		border: none;
	}

	.titleBox {
		width: 100%;
		padding-left: 20rpx;
		color: var(--color);
		font-size: 30rpx;
		position: relative;
	}

	.titleBox::before {
		content: '';
		width: 4rpx;
		height: 30rpx;
		background-color: var(--color);
		position: absolute;
		left: 0;
		top: 50%;
		transform: translate(0, -50%);
	}

	.serveList {
		width: 100%;
		padding: 20rpx 0;
		display: flex;
		position: relative;
	}

	.product {
		width: 170rpx;
		height: 170rpx;
		border: 1px solid #f7f7f7;
		border-radius: 10rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		overflow: hidden;
		position: relative;

		&-img {
			width: 100%;
			height: 100%;
		}

		.serial {
			background-color: var(--color);
			padding: 2rpx 20rpx;
			color: #ffffff;
			font-size: 22rpx;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 10;
			border-radius: 0 0 10rpx 0;
		}
	}

	.product_content {
		flex: 1;
		height: 180rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-left: 24rpx;
	}

	.look {
		width: 160rpx;
		height: 60rpx;
		border: 1rpx solid #f2f2f2;
		display: flex;
		justify-content: center;
		align-items: center;
		color: var(--color);
		font-size: 24rpx;
		border-radius: 30rpx;
	}

	.title {
		color: #000;
	}

	.Abstract {
		color: #333333;
	}

	.price {
		color: #990000;
	}

	.product_content_buy {
		flex: 1;
		display: flex;
		margin-left: 24rpx;

		.Options {
			display: flex;
			flex-direction: column;
			justify-content: space-evenly;

			&-list {
				width: 160rpx;
				height: 60rpx;
				border: 1px solid #f2f2f2;
				display: flex;
				justify-content: center;
				align-items: center;
				color: var(--color);
				font-size: 24rpx;
				border-radius: 30rpx;
				position: relative;
				overflow: hidden;

				.shareBtn {
					width: 100%;
					height: 100%;
					position: absolute;
					top: 0;
					left: 0;
					z-index: 10;
					background-color: transparent;
				}
			}
		}
	}

	.Used {
		.serial {
			background-color: #ccc;
		}

		.product_img {
			opacity: 0.5;
		}

		.title,
		.price {
			color: #ccc;
		}

		.Options-list {
			color: #ccc;
		}

		.icon-yishiyong {
			position: absolute;
			font-size: 120rpx;
			left: 22%;
			top: 50%;
			transform: translate(0, -50%);
			z-index: 10;
		}
	}

	.Pop {
		width: 100%;
		height: 100vh;
		position: fixed;
		inset: 0;
		z-index: 100;
		background-color: rgba(0, 0, 0, 0.2);
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}
</style>